package com.zhuxulin.tab.listeners;

import android.view.View;
import android.view.View.OnClickListener;

import com.zhuxulin.tab.bluetooth.ISendMsg;
import com.zhuxulin.tab.threads.PlayMidOnPiano;
import com.zhuxulin.tab.utils.LogUtils;

public class SendMsgListener implements OnClickListener {
	private static final String TAG = SendMsgListener.class.getSimpleName();
	private ISendMsg sendMsg = null;

	public SendMsgListener(ISendMsg sendMsg) {
		this.sendMsg = sendMsg;
		LogUtils.i(TAG, "Set sendMsg:"+this.sendMsg.toString());
	}

	@Override
	public void onClick(View v) {
		LogUtils.i(TAG, "Send msg!");
//		// Note on
//		sendMsg.sendMessage(0x90);
//		// Note 3C
//		sendMsg.sendMessage(0x3C);
//		// Note off
//		sendMsg.sendMessage(0x7F);
//		sendMsg.sendMessage(CloseChannelEventData.closeALL());
//		Mid mid=new Mid("/mnt/sdcard/Music/1.mid");
//		List<Event> event = mid.getTrackEvent(1);
		new PlayMidOnPiano(sendMsg).start();
		
		
//		sendMsg.sendMessage(event.get(3).getMsg());
//		new SendMsgThread(sendMsg, event).start();
		
//		new SendMsgThread(sendMsg, new int[] { 0x90, 0x3C, 0x7F, 0x91, 0x3C, 0x7F,
//				0x92, 0x3C, 0x7F, 0x93, 0x3C, 0x7F}).start();
//		sendMsg.sendMessage(Mid1.i1);
		/**new Thread(new Runnable() {
			@Override
			public void run() {
				Looper.prepare();
				sendMsg.sendMessage(Mid1.i1);
				
				byte[] b = new byte[1024];
				InputStream in = null;
				try {
					LogUtils.i(TAG, Environment.getExternalStorageDirectory()
							.getPath());
					in = new FileInputStream(
							new File("/mnt/sdcard/Music/1.mid"));
					while (in.read(b) != -1) {
						sendMsg.sendMessage(b);
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}).start();*/
	}

}
